home *** CD-ROM | disk | FTP | other *** search
/ El Mac 9 / El Mac 9.iso / Shareware / Applications / MathPad 2.4 / Examples / harmonics < prev    next >
Encoding:
Text File  |  1996-04-02  |  682 b   |  26 lines  |  [TEXT/MPad]

  1. -- Show additive waveform synthesis.
  2. -- Requires XFuns "sliders" and "playsynth"
  3.  
  4. -- Create a signal by adding n sine waves.
  5. -- Each has a different frequency f and amplitude c[f]
  6.  n=4
  7.  sig(t) = sum(c[f]*sin(2*π*f*t),f,1,n)
  8.  
  9. -- use a slider bar to set each amplitude
  10.  sliders[i] = slider(i,0,1) dim[n]
  11.  c:= sliders:;
  12.  label c:{0.50,0.50,0.50,0.50}
  13.  Xmin=0; Xmax=1; Ymin=-2; Ymax=2
  14.  plot sig(X)
  15.  
  16. -- slider values of {1, 0, .15, 0} approximate a square wave, {1, .3, .06, .02} for sawtooth
  17.  
  18. -- sample sig(t) for the sound synthesizer
  19. samp[i] = sig((i-1)/511) dim[512]
  20.  
  21. note := slider("note",50,100):
  22. amp := slider("volume",0,1):
  23.  
  24. (loadsynth(samp),
  25.  playsynth(note,2,amp)) when amp>0:
  26.